﻿using Acme.BookStore2;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity;

namespace Volo.Abp.AuditLogging
{
    public class AuditLogAppService : BookStore2AppService, IAuditLogAppService
    {
        private readonly IAuditLogRepository _auditLogRepository;
        

        public AuditLogAppService(IAuditLogRepository auditLogRepository)
        {
            this._auditLogRepository = auditLogRepository;
        }

        public async Task<AuditLogDto> GetAsync(Guid id)
        {
            return ObjectMapper.Map<AuditLog, AuditLogDto>(await _auditLogRepository.GetAsync(id));
        }

        public async Task<PagedResultDto<AuditLogDto>> GetListAsync(GetAuditLogsInput input)
        {
            var count = await _auditLogRepository.GetCountAsync(input.StartTime, input.EndTime, input.HttpMethod, input.Url, input.UserName, input.ApplicationName, input.CorrelationId, input.MaxExecutionDuration, input.MinExecutionDuration, input.HasException, input.HttpStatusCode);
            var list = await _auditLogRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.StartTime, input.EndTime, input.HttpMethod, input.Url, input.UserName, input.ApplicationName, input.CorrelationId, input.MaxExecutionDuration, input.MinExecutionDuration, input.HasException, input.HttpStatusCode);
            return new PagedResultDto<AuditLogDto>(count,ObjectMapper.Map<List<AuditLog>, List<AuditLogDto>>(list));
        }
    }
}
